Make sparse and spdiagm statically dispatchable / --trim compatible - #751
Conversation
|
Tests for trimmability will be added downstream in the Julia dep bump |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #751 +/- ##
==========================================
- Coverage 84.39% 83.85% -0.55%
==========================================
Files 13 13
Lines 9382 9387 +5
==========================================
- Hits 7918 7871 -47
- Misses 1464 1516 +52 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Is this good to merge? |
|
It is from my POV but I do not have merge permissions. @dkarrasch ? |
|
@dkarrasch is taking a break. Can't you add an |
|
We could, but |
|
As far as I understand what wasn't well-inferred before was the eltype of |
Two constructors defeated static call resolution (e.g. under juliac's
`--trim`) for reasons invisible at the call site:
The `sparse(I, J, V, m, n, combine)` methods took `combine` as an
unconstrained, unspecialized argument, so the pass-through call into the
`Tv`/`Ti`-typed method was made on an abstractly-typed function value.
Parameterizing the methods on `combine::F` specializes the pass-through
and the call chain resolves statically.
`spdiagm`'s eltype computation mapped `eltype` over the `kv::Pair...`
tuple; under Vararg widening the compiled signature is
`(::Pair, ::Vararg{Pair})`, for which the tuple `map` itself cannot be
resolved. A dispatch-based `spdiagm_eltype` (pairwise recursion, with a
homogeneous fast path that binds the common eltype) mirrors
`Base.promote_eltypeof` and resolves statically for every arity.
Both changes only sharpen dispatch; behavior is unchanged. Compiling
A = sparse([1, 2, 3], [1, 2, 3], [1.0, 2.0, 3.0])
B = spdiagm(0 => ones(3), 1 => ones(2))
with `juliac --output-exe --trim=safe` fails before this change with ten
verifier errors (unresolved `sparse!`, the tuple `map`, its
`_apply_iterate` splat, and a `Vector{_A}` allocation whose type never
became concrete) and verifies cleanly with it.
This commit was written with the assistance of generative AI (Claude).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
c4aa0b7 to
e8dc728
Compare
|
|
|
Thanks. It's not quite what we needed but it'll have to do. |
This allows these basic SparseArrays constructors to be
--trimcompatible:This commit was written with the assistance of generative AI (Claude) 🤖